using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Net.Sockets;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
using System.Diagnostics;
using System.Configuration;
using MySql.Data.MySqlClient;
using SamasDBI;
using SamasDBI.MySQL;
using SamasUtilities;

namespace EQEmuMysql
{
    public class Lists
    {
        /*******************
         * Petitions Sorted List
         *******************/ 
        public static SortedList<int, Petitions> PetitionList()
        {
            SortedList<int, Petitions> lsPetitions = new SortedList<int, Petitions>();
            MySqlConnection conGet = new MySqlConnection(MySQLRunner.ConnectionString);
            MySqlDataReader drGet = null;
            string sSQL = "";
            Petitions oPetition;

            sSQL = "SELECT petid FROM petitions";

            if (MySQLRunner.ExecuteQuery(sSQL, conGet, ref drGet) == true)
            {

                while (drGet.Read())
                {
                    oPetition = new Petitions(drGet.GetInt32(drGet.GetOrdinal("petid")));
                    lsPetitions.Add(oPetition.ID, oPetition);
                }
            }
            else
            {
                MessageBox.Show("Error connecting to the database.");
            }

            if (conGet.State == ConnectionState.Open)
            {
                if (drGet != null)
                    drGet.Close();

                conGet.Close();
            }
            return lsPetitions;
        }
        /*******************
         * Petitions Sorted List
         *******************/
        public static SortedList<int, Accounts> AccountList()
        {
            SortedList<int, Accounts> lsAccounts = new SortedList<int, Accounts>();
            MySqlConnection conGet = new MySqlConnection(MySQLRunner.ConnectionString);
            MySqlDataReader drGet = null;
            string sSQL = "";
            Accounts oAccount;

            sSQL = "SELECT id FROM account";

            if (MySQLRunner.ExecuteQuery(sSQL, conGet, ref drGet) == true)
            {

                while (drGet.Read())
                {
                    oAccount = new Accounts(drGet.GetInt32(drGet.GetOrdinal("id")));
                    lsAccounts.Add(oAccount.ID, oAccount);
                }
            }
            else
            {
                MessageBox.Show("Error connecting to the database.");
            }

            if (conGet.State == ConnectionState.Open)
            {
                if (drGet != null)
                    drGet.Close();

                conGet.Close();
            }
            return lsAccounts;
        }

        /*******************
        * Variables Sorted List
         *******************/ 
        public static SortedList<string, Variables> VariableList()
        {
            SortedList<string, Variables> lsVariables = new SortedList<string, Variables>();
            MySqlConnection conGet = new MySqlConnection(MySQLRunner.ConnectionString);
            MySqlDataReader drGet = null;
            string sSQL = "";
            Variables oVariable;

            sSQL = "SELECT varname FROM variables";

            if (MySQLRunner.ExecuteQuery(sSQL, conGet, ref drGet) == true)
            {

                while (drGet.Read())
                {
                    oVariable = new Variables(drGet.GetString(drGet.GetOrdinal("varname")));
                    lsVariables.Add(oVariable.VarName, oVariable);
                }
            }
            else
            {
                MessageBox.Show("Error connecting to the database.");
            }

            if (conGet.State == ConnectionState.Open)
            {
                if (drGet != null)
                    drGet.Close();

                conGet.Close();
            }
            return lsVariables;
        }
        /*******************
        * Variables Sorted List
         *******************/
        public static SortedList<string, Rules> RuleList()
        {
            SortedList<string, Rules> lsRules = new SortedList<string, Rules>();
            MySqlConnection conGet = new MySqlConnection(MySQLRunner.ConnectionString);
            MySqlDataReader drGet = null;
            string sSQL = "";
            Rules oRule;

            sSQL = "SELECT rule_name FROM rule_values where ruleset_id = '" + System.Configuration.ConfigurationManager.AppSettings["ruleset"] + "'";

            if (MySQLRunner.ExecuteQuery(sSQL, conGet, ref drGet) == true)
            {

                while (drGet.Read())
                {
                    oRule = new Rules(drGet.GetString(drGet.GetOrdinal("rule_name")));
                    lsRules.Add(oRule.RuleName, oRule);
                }
            }
            else
            {
                MessageBox.Show("Error connecting to the database.");
            }

            if (conGet.State == ConnectionState.Open)
            {
                if (drGet != null)
                    drGet.Close();

                conGet.Close();
            }
            return lsRules;
        }
    }//class
}
